package org.liveboardgames.agricola.control.delegates
{
    import com.adobe.cairngorm.business.ServiceLocator;
    
    import flash.utils.setTimeout;
    
    import mx.rpc.IResponder;
    
    import org.liveboardgames.agricola.model.AgricolaModelLocator;
    import org.liveboardgames.agricola.model.enums.HarvestStepEnum;
    import org.liveboardgames.agricola.vo.player.Player;
    
    public class HarvestStepCompleteDelegate
    {
        private var _responder:IResponder;
        
        private var _service:Object;
        
        public function HarvestStepCompleteDelegate(responder:IResponder)
        {
            this._service = ServiceLocator.getInstance().getRemoteObject( "harvestService" );
            this._responder = responder;
        }
        
        /** Used only to signal end of harvest for one player.*/
        public function harvestStepComplete(player:Player, step:String):void
        {
        	var call:Object = _service.harvestStepComplete(AgricolaModelLocator.getInstance().game.id, player.id);
			call.resultHandler = _responder.result;
			call.faultHandler = _responder.fault;
//            setTimeout(harvestStepCompleteService, 0, player, step);
        }
        
        private function harvestStepCompleteService(player:Player, step:String):void
        {
            if (HarvestStepEnum.FEED == step)
            {
                AgricolaModelLocator.getInstance().game.harvestFeedPlayers.addItem(player);
            }
            else if (HarvestStepEnum.BREED == step)
            {
                AgricolaModelLocator.getInstance().game.harvestBreedPlayers.addItem(player);
            }
        }
    }
}